package com.csmarket.csmarketbackend.controller;

import com.csmarket.csmarketbackend.common.Result;
import com.csmarket.csmarketbackend.server.WebSocketEndPoint;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

@RestController
@RequestMapping("/api")
public class MessageController {
    @GetMapping("/online-users")
    public  Result<Map<String, Object>> getOnlineUsers() {
        Set<String> onlineUsers = WebSocketEndPoint.getOnlineUsers();
        Map<String, Object> response = new HashMap<>();
        response.put("onlineUsers", onlineUsers);
        response.put("count", onlineUsers.size());
        return Result.success(response);
    }
}
